package cn.lili.modules.permission.entity.vo;

import cn.lili.common.utils.BeanUtil;
import cn.lili.modules.permission.entity.dos.Menu;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 菜单VO 展示模型
 *
 * @author Chopper
 * @since 2020/11/20 15:38
 */

@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Data
public class MenuVO extends Menu {

    @Serial
    private static final long serialVersionUID = 7429463559431046912L;

    @ApiModelProperty(value = "子菜单")
    private List<MenuVO> children = new ArrayList<>();

    public MenuVO(Menu menu) {
        BeanUtil.copyProperties(menu, this);
    }

    public List<MenuVO> getChildren() {
        if (children != null) {
            children.sort(Comparator.comparing(Menu::getSortOrder));
            return children;
        }
        return null;
    }
}
